package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.pasture.PastureAnimalData;
import com.yanqu.road.entity.activity.pasture.cross.CrossPastureUserData;
import com.yanqu.road.pb.activity.PastureProto;

public class CrossPasturePb {

    /**
     * 用户数据
     */
    public static PastureProto.PastureUserDataTemp.Builder parseUserDataTemp(CrossPastureUserData userData) {
        if (userData == null) {
            return null;
        }
        PastureProto.PastureUserDataTemp.Builder builder = PastureProto.PastureUserDataTemp.newBuilder();
        builder.setMaxScore(userData.getMaxScore());
        builder.setTodayTimes(userData.getTodayTimes());
        // 游戏数据
        PastureProto.PastureGameDataTemp.Builder gameDataTemp = PasturePb.parseGameDataTemp(userData.getGameData());
        if (gameDataTemp != null) {
            builder.setGameData(gameDataTemp);
        }
        // 练习模式数据
        PastureProto.PastureGameDataTemp.Builder parseGameDataTemp = PasturePb.parseGameDataTemp(userData.getPracticeData());
        if (parseGameDataTemp != null) {
            builder.setPracticeData(parseGameDataTemp);
        }
        // 动物数据
        for (PastureAnimalData animalData : userData.getAnimalDataMap().values()) {
            builder.addAnimalData(PasturePb.parseAnimalDataTemp(animalData));
        }
        builder.setUpdateTime(userData.getUpdateTime());
        builder.setResetTime(userData.getResetTime());
        builder.setIsBuySilverToken(userData.isBuySilverToken());
        builder.setIsBuyGoldToken(userData.isBuyGoldToken());
        builder.setCanRevive(userData.isCanRevive());
        builder.setLastMaxScore(userData.getLastMaxScore());
        builder.setFinishGuide(userData.isFinishGuide());
        return builder;
    }

}
